package com.health.platform.provider.hygieneemergency.serivce;

import com.health.platform.common.core.entity.BaseQueryEntity;
import com.health.platform.common.restful.AppResponse;
import com.health.platform.common.sys.dict.dao.DictDao;
import com.health.platform.common.sys.dict.entity.DictEntity;
import com.health.platform.common.sys.organization.dao.OrganizationMapper;
import com.health.platform.common.sys.organization.entity.OrganizationEntity;
import com.health.platform.provider.hygieneemergency.dao.HygieneEmeDao;
import com.health.platform.provider.hygieneemergency.entity.BloodStockEntity;
import com.health.platform.provider.hygieneemergency.entity.EmeMaterialRateEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import com.health.platform.common.sys.organization.entity.UnitEntity;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>卫生应急Service</p>
 * <p>创建日期：2021-02-27</p>
 *
 * @author zhou-qf
 */
@Service
public class HygieneEmeService {

    @Resource
    private HygieneEmeDao hygieneEmeDao;

    @Resource
    private DictDao dictDao;


    /**
     * 获取汇总信息
     * @param baseQueryEntity 参数
     * @return 结果
     */
    public AppResponse getSummary(BaseQueryEntity baseQueryEntity){
        return AppResponse.success("查询成功", hygieneEmeDao.getSummary(baseQueryEntity));
    }

    /**
     * 获取血液库存信息
     * @param baseQueryEntity 参数
     * @return 结果
     */
    public AppResponse getBloodStock(BaseQueryEntity baseQueryEntity){
        Map<String, Object> map = new HashMap<>(2);
        List<BloodStockEntity>  bsList= hygieneEmeDao.getBloodStock(baseQueryEntity);


        UnitEntity unitEntity=new UnitEntity();
        unitEntity.setSgbCode(baseQueryEntity.getSgbCodeStandby());
        System.out.println(unitEntity.getSgbCode());
        List<UnitEntity> institutionslist=hygieneEmeDao.getUnit(unitEntity);
        DictEntity dictEntity=new DictEntity();
        dictEntity.setType("DM_SXPZ");
        List<DictEntity> typeslist= dictDao.getDict(dictEntity);
        dictEntity.setType("DM_ABO");
        List<DictEntity> bloodTypelist= dictDao.getDict(dictEntity);
        List<BloodStockEntity>  bs= hygieneEmeDao.getBS();
        map.put("bs", bs);
        map.put("types", typeslist);
        map.put("bloodType",bloodTypelist);
        map.put("list", hygieneEmeDao.getBloodStock(baseQueryEntity));
        map.put("groupDetail", hygieneEmeDao.getBloodRate(baseQueryEntity));
        map.put("institutions", institutionslist);
        return AppResponse.success("查询成功", map);
    }

    /**
     * 获取应急物资列表信息
     * @param baseQueryEntity 参数
     * @return 结果
     */
    public AppResponse getEmeMaterial(BaseQueryEntity baseQueryEntity){
        Map<String, Object> map = new HashMap<>(2);
        map.put("list", hygieneEmeDao.getEmeMaterial(baseQueryEntity));
        // 物资类型
        map.put("suppliesType", hygieneEmeDao.getSuppliesType(baseQueryEntity));
        Map<String, Object> mapGd = new HashMap<>(2);
        EmeMaterialRateEntity erEntity= hygieneEmeDao.getEmeMaterialRate(baseQueryEntity);
        if(erEntity==null){
            erEntity=new EmeMaterialRateEntity();
        }
        mapGd.put("防护用品",erEntity.getType1());
        mapGd.put("临时食宿",erEntity.getType5());
        mapGd.put("污染清理",erEntity.getType6());
        mapGd.put("动力燃料",erEntity.getType7());
        mapGd.put("工程设备",erEntity.getType8());
        mapGd.put("器材工具",erEntity.getType9());
        mapGd.put("照明设备",erEntity.getType10());
        mapGd.put("通讯广播",erEntity.getType11());
        mapGd.put("交通运输",erEntity.getType12());
        mapGd.put("工程材料",erEntity.getType13());

        map.put("groupDetail",mapGd );
        return AppResponse.success("查询成功", map);
    }

    /**
     * 获取急救车辆列表信息
     * @param baseQueryEntity 参数s
     * @return 结果
     */
    public AppResponse getEmeCar(BaseQueryEntity baseQueryEntity){
        baseQueryEntity.setSgbCodeStandby(baseQueryEntity.getSgbCode().replaceAll("t.GBCODE","t1.sgbcode"));
        return AppResponse.success("查询成功", hygieneEmeDao.getEmeCar(baseQueryEntity));
    }

    /**
     * 获取床位管理列表信息
     * @param baseQueryEntity 参数
     * @return 结果
     */
    public AppResponse getBedNum(BaseQueryEntity baseQueryEntity){
        return AppResponse.success("查询成功", hygieneEmeDao.getBedNum(baseQueryEntity));
    }
}
